package com.project_doctor.mapper;

import com.project_doctor.pojo.AnnouncementReceiver;
import com.project_doctor.pojo.Dto.AnnRequest;
import com.project_doctor.pojo.SystemAnnouncement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
/**
* @author 龙龙与贝儿
* @description 针对表【t_system_announcement】的数据库操作Mapper
* @createDate 2025-06-03 10:32:05
* @Entity com.project_doctor.pojo.SystemAnnouncement
*/
public interface SystemAnnouncementMapper extends BaseMapper<SystemAnnouncement> {

    @Select("SELECT a.*,d.id as doctor_id, d.name AS doctor_name, r.id as role_id, r.role_name as role_name " +
            "FROM t_system_announcement a " +
            "LEFT JOIN t_doctor d ON a.doctor_id_send=d.id " +
            "LEFT JOIN t_role r ON a.role_id=r.id " +
            "WHERE a.id = #{id}")
    @Results({
            @Result(property = "doctor.id", column = "doctor_id"),
            @Result(property = "doctor.name", column = "doctor_name"),
            @Result(property = "receiverIds", column = "receiver_ids"), // 添加receiverIds映射
            @Result(property = "role.id", column = "role_id"),
            @Result(property = "role.roleName", column = "role_name")

    })
    SystemAnnouncement getAnnByIdWithName(@Param("id") Long id);

    List<SystemAnnouncement> selectAllWithNameAndRole(AnnRequest annRequest);

    void batchNewAnnouncement(List<SystemAnnouncement> dataList);

    // 自定义查询方法
    @Select("SELECT * FROM t_system_announcement WHERE id = #{id}")
    SystemAnnouncement selectAnnouncementWithReceivers(@Param("id") Long id);

}




